import {LOGIN, LOGINFAIL, LOGINSUCCESS, LOGOUT, LOGOUTFAIL, LOGOUTSUCCESS,} from "@/stores/actionTypes/loginActionType";
import {ILoginReducerState} from "@/stores/reducers/loginReducers";

export interface ILoginPayload {
    username: string
    password: string
    code?: string
    uuid?: string
}

export interface ILoginAction {
    type: typeof LOGIN
    payload: ILoginPayload
}

export const loginAction = (payload: ILoginPayload): ILoginAction => ({
    type: LOGIN,
    payload
})

export interface ILoginSuccessAction {
    type: typeof LOGINSUCCESS
    payload: ILoginReducerState
}

export const loginSuccessAction = (payload: ILoginReducerState): ILoginSuccessAction => ({
    type: LOGINSUCCESS,
    payload
})

export interface ILoginFailAction {
    type: typeof LOGINFAIL
    message: string
}

export const loginFailAction = (message: string): ILoginFailAction => ({
    type: LOGINFAIL,
    message
})

export interface ILogoutAction {
    type: typeof LOGOUT
}

export const logoutAction = (): ILogoutAction => ({
    type: LOGOUT
})

export interface ILogoutSuccessAction {
    type: typeof LOGOUTSUCCESS
}

export const logoutSuccessAction = (): ILogoutSuccessAction => ({
    type: LOGOUTSUCCESS
})

export interface ILogoutFailAction {
    type: typeof LOGOUTFAIL,
    message: string
}

export const logoutFailAction = (message: string): ILogoutFailAction => ({
    type: LOGOUTFAIL,
    message
})

export type LoginAction =
    ILoginAction
    | ILoginSuccessAction
    | ILoginFailAction
    | ILogoutAction
    | ILogoutSuccessAction
    | ILogoutFailAction
